from django import forms
from .bootstrap import BootStrapFrom
from web import models


class WikiAddModelForm(BootStrapFrom, forms.ModelForm):
    class Meta:
        model = models.Wiki
        exclude = ['project','depth']

    # 保证父级文章是此项目所拥有的
    # 重写init方法
    def __init__(self, request, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # 获取该项目所拥有的wiki文档
        total_data_list = [('', '选填'), ]
        data_list = models.Wiki.objects.filter(project=request.tracer.project).values_list('id', 'title')
        total_data_list.extend(data_list)
        # 找到想要展示字段的数据，进行自定义重置
        self.fields['parent'].choices = total_data_list
